﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SPMS.Common
{
    /// <summary>
    /// 反权限要求。
    /// </summary>
    public sealed class NotPermissionRequirement
    {
        #region ---Constructor

        /// <summary>
        /// 初始化类型<see cref="NotPermissionRequirement" />的新实例。
        /// </summary>
        /// <param name="requirement">权限要求。</param>
        /// <exception cref="System.ArgumentNullException">当<see cref="requirement"/>为<c>null</c>时，抛出此异常。</exception>
        public NotPermissionRequirement(IPermissionRequirement requirement)
        {
            //判断参数
            if (null == requirement)
            {
                //抛出异常
                throw new ArgumentNullException("requirement");
            }

            //保存参数
            this.m_Requirement = requirement;
        }

        #endregion

        #region ---IPermissionRequirement

        /// <summary>
        /// 判断当前登录用户是否满足功能权限要求。
        /// </summary>
        /// <param name="principal">窗体认证用户信息。</param>
        /// <returns>
        /// 如果满足，则返回<c>true</c>，否则返回<c>false</c>。
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public bool IsValid(FormsPrincipal principal)
        {
            //返回结果
            return !this.m_Requirement.IsValid(principal);
        }

        #endregion

        #region ---Field

        /// <summary>
        /// 权限要求。
        /// </summary>
        private IPermissionRequirement m_Requirement;

        #endregion
    }
}
